﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Mvc;
using T.ApiResults;
using T.Vehicleservice.Domain.Dtos;
using T.Vehicleservice.Domain.T.Vehicleservice.Model;
using T.Vehicleservice.Read.API.Application.Command.MaintenanceRecordCommand;
using T.Vehicleservice.Read.API.Server;

namespace T.Vehicleservice.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MainController : ControllerBase
    {

        private readonly  IMediator mediators;
        HttpCar httpCar;

        public MainController(IMediator mediators, HttpCar httpCar)
        {
            this.mediators = mediators;
            this.httpCar = httpCar;
        }

        /// <summary>
        /// 显示车牌号
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet]

        public async Task<IActionResult> GetCar()
        {

            try
            {
                return Ok(await httpCar.GetCar());
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示维修记录
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDto<MaintenanceRecord>>> MShowMain([FromQuery]MainShowCommand command)
        {
            ApiResult<PageDto<MaintenanceRecord>> result = new ApiResult<PageDto<MaintenanceRecord>>();
            try
            {
                result.Data = await mediators.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
        /// <summary>
        /// 反填维修信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MaintenanceRecord> MaintRecord([FromQuery] MainBackfillCommand command)
        {
            try
            {
                return await mediators.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
